﻿module Sustainalytics.Screening {

    import Common = Sustainalytics.Common;
    import SearchBox = Sustainalytics.SearchBox;


    export interface IScreeningToolSearchBoxService {
        // Search for items given a term and paging options
        Search(): ng.IHttpPromise<any[]>;
    }


    export class UniverseSearchBoxServiceAdapter implements IScreeningToolSearchBoxService {

        private _http: ng.IHttpService;
        private _idAccount:string;
        public constructor(http, $rootScope: ng.IScope) {
            this._http = http;
            this._idAccount = $rootScope['userInfo'].accountId;
        }

        public Search(): ng.IHttpPromise<any[]> {
            if (navigator.appVersion.indexOf("MSIE 9.") != -1 || navigator.appVersion.indexOf("MSIE 10") != -1) { //todo right now is just a hack and a hard-coded version if it changes it should reference the link built in screening tool factory same as criteriasearchboxservadapter

                var url = "/universesserv/api/v1/universes/" + this._idAccount;
                return this._http.get(url);
            }
            var lstPromise: ng.IHttpPromise<any[]> = this._http.get("");
            return lstPromise;
        }
    }


    var mod = angular.module(screeningToolModuleName);

    mod.service('UniverseSearchBoxServiceAdapter',
        ['$http','$rootScope', UniverseSearchBoxServiceAdapter]);
}